﻿layui.use(['form', 'layer', 'jquery', 'laypage'], function () {
    var form = layui.form,
		layer = parent.layer === undefined ? layui.layer : parent.layer,
		laypage = layui.laypage,
		$ = layui.jquery;
    function Select() {
        var url = "/TasksManagement/Select";
        $.post(url, function (result) {
            var departments = JSON.parse(result.data);
            var deptSelect = $("#deptSelect");
            layui.each(departments, function (index, data) {
                var deptOption = $("<option value='" + data.Id + "'>" + data.TaskTypeName + "</option>");
                deptSelect.append(deptOption);
            });
            form.render();
        });
    };
    function AddSubmit(data) {
        $.ajax({
            type: "post",
            url: "/TasksManagement/Tasks_Add",
            data: data.field,
            dataType: "json",
            success: function (result) {
                if (result.State == 1)
                    layer.alert(result.Message, { icon: 1,time:1.5*1000 });
                else
                    layer.msg(result.Message, { icon: 7, time: 1.5 * 1000 });
            }
        });
    };
        $(function () {
            Select();
            //监听提交  subForm为lay-filter属性
            form.on('submit(subForm)', function (data) {
                AddSubmit(data);
                return false;
            });
        });
   
    });